﻿Public Class WfOS
    Inherits System.Web.UI.Page
    Dim despLogado As New Despachante

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("DespLogado") Is Nothing Then
            Response.Redirect("/Screens/WF1.aspx")
        End If

        despLogado = Session("DespLogado")
        If IsPostBack = False Then
            populaStatus()
        End If

        Dim objOs As New Os
        Dim objOsDao As New OsDAO
        Dim cod_os As Integer = Request.QueryString("CodOs")
        objOs = objOsDao.SelectOsId(cod_os, despLogado)

        TbNomeCli.Text = objOs.Cliente.NomeCli
        TbData.Text = objOs.DataOs
        TbOBS.Text = objOs.ObsOs
        TbPagamento.Text = objOs.PgtOs
        TbServ.Text = objOs.Servico.DescServ
        TbValor.Text = objOs.ValorOs
        tbstatus.Text = objOs.Status.DescStat
    End Sub


    Private Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
        If Session("DespLogado") Is Nothing Then
            Response.Redirect("/Screens/WF1.aspx")
        End If
    End Sub

    Public Sub populaStatus()
        Dim StatusDao As New Status_osDAO
        Dim lista As New List(Of Status_Os)

        lista = StatusDao.ListaTodos
        For Each sta As Status_Os In lista
            DropStatus.Items.Add(sta.DescStat)
        Next
    End Sub

    Protected Sub BtnSalvar_Click(sender As Object, e As EventArgs) Handles BtnSalvar.Click
        Try
            Dim objOs As New Os
            Dim objOsDao As New OsDAO
            Dim StatusDao As New Status_osDAO
            Dim status As New Status_Os

            status.DescStat = DropStatus.SelectedItem.Text
            objOs.CodOs = Request.QueryString("CodOs")
            objOs.Status = StatusDao.selectStatusDesc(status)

            objOsDao.Atualizar(objOs)
            lbmsg.ForeColor = Drawing.Color.Blue
            lbmsg.Text = " Ordem de Serviço Atulizado com Sucesso !"
            BtnSalvar.Enabled = False
            DropStatus.Enabled = False
        Catch ex As Exception
            lbmsg.ForeColor = Drawing.Color.Red
            lbmsg.Text = " Erro ao Atualizar Ordem de Serviço !"
        End Try
       

    End Sub
End Class